#include <vector>
#include <iostream>
using namespace std;
class Solution
{
public:
    int singleNonDuplicate(vector<int> &nums)
    {
        int len = nums.size();
        int l = 0, r = len - 1;
        int mid;
        while (l < r)
        {
            mid = (l + r) / 2;
            if (nums[mid] == nums[mid - 1])
            {
                if ((r - mid) & 1)
                {
                    l = mid + 1;
                }
                else
                {
                    r = mid - 2;
                }
            }
            else if (nums[mid] == nums[mid + 1])
            {
                if ((mid - l) & 1)
                {
                    r = mid - 1;
                }
                else
                {
                    l = mid + 2;
                }
            }
            else
            {
                return nums[mid];
            }
        }
        return nums[l];
    }
};
int main(int argc, char const *argv[])
{
    Solution s;
    vector<int> v({3, 3, 7, 7, 10, 11, 11});
    cout << s.singleNonDuplicate(v) << endl;
    return 0;
}
